#include "particle.h"
#include "custom_utils.h"

// real functions

/*
 * Updates the particle by doing all the physics simulations.
 */
void Particle::update(double timeScale) {
    if (locked) {
        return;
    }
    x = x + vx * timeScale;
    y = y + vy * timeScale;
}

/*
 * F = ke((Q1 * Q2) / r^2)
 * F = a
 * vf = vi + at
 */
void Particle::beAwareOf(double x_, double y_, double charge_, double timeScale) {
    double F, Fx, Fy, ds, d;
    ds = distanceSq(x_, y_, x, y);
    if (ds < 100) {
        ds = 100;
    }
    F = (8.988e9) * ((charge * charge_) / ds);
    d = distance(x_, y_, x, y);
    if (d < 100) {
        d = 100;
    }
    Fx = (x - x_) * (F / d);
    Fy = (y - y_) * (F / d);
    vx = vx + Fx * timeScale;
    vy = vy + Fy * timeScale;
}


// functions that deal with variables

// Get
double Particle::get_x() {
        return x;
}

double Particle::get_y() {
    return y;
}

double Particle:: get_vx() {
    return vx;
}

double Particle:: get_vy() {
    return vy;
}

double Particle::get_charge() {
    return charge;
}

bool Particle::get_locked() {
    return locked;
}

// Set
Particle::Particle() {
    x = 0;
    y = 0;
    vx = 0;
    vy = 0;
    charge = 0;
    next = 0;
    locked = false;
}

void Particle::set_x(double x_) {
    x = x_;
}

void Particle::set_y(double y_) {
    y = y_;
}

void Particle::set_charge(double charge_) {
    charge = charge_;
}

void Particle::set_vx(double vx_) {
    vx = vx_;
}

void Particle::set_vy(double vy_) {
    vy = vy_;
}

void Particle::set_locked(bool locked_) {
    locked = locked_;
}
